package org.BooCrack.bookstore.pay.controller.admin;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.BooCrack.bookstore.common.utils.Response;
import org.BooCrack.bookstore.common.utils.ResponseResult;
import org.BooCrack.bookstore.model.entity.Store;
import org.BooCrack.bookstore.model.service.IBookInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
//@RequestMapping("/admin/report")
@RequestMapping("admin/V6")
@RequiresPermissions("store-manage")
@Api(value = "v1", tags = "8-4.后台管理系统报告模块接口")
public class ReportController {

    @Autowired
    private IBookInfoService bookInfoService;

    /**
     * 商店书籍访问量排行饼图
     * @return
     */
    @GetMapping("/views/pie")
    @ApiOperation(value = "商店书籍访问量排行", notes = "商店书籍访问量排行")
    public ResponseResult getBookViewsPieJson(HttpSession session){
        Store loginStore = (Store) session.getAttribute("loginStore");
        if(loginStore == null){
            return Response.createFailResp("未找到商店");
        }
        return Response.createOkResp(bookInfoService.getBookViewsPiesByStoreId(loginStore.getStoreId()));
    }

    @GetMapping("/sales/bar")
    @ApiOperation(value = "商店书籍销售量排行", notes = "商店书籍销售量排行")
    public ResponseResult getBookSalesBarJson(HttpSession session){
        Store loginStore = (Store) session.getAttribute("loginStore");
        if(loginStore == null){
            return Response.createFailResp("未找到商店");
        }
        return Response.createOkResp(bookInfoService.getBookSalesBarJson(loginStore.getStoreId()));
    }


}
